﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace XMLSchemaExtractor
{
    class DEntity : ORASSDrawing
    {
        private int _x;
        private int _y;
        private string _entityName;
        private DEntity _parent;
        private int _width;
        //have to put diff types for multiple relations
        //attribute entityRelations;

        public int x
        {
            get
            {
                return _x;
            }
        }

        public int y
        {
            get
            {
                return _y;
            }
        }
        public int width
        {
            get
            {
                return _width;
            }
        }
        public String Name
        {

            get
            {

                return _entityName;

            }
        }
        public DEntity Parent
        {

            get{

                return _parent;

            }
        }
        public DEntity(string entityName, int x, int y, DEntity parent,int count, int position)
        {
            _entityName = entityName;
            _x = x+(120*position);
            _y = y +(20*count);
            _parent = parent;
            _width = _entityName.Length * 10;
        }
        public void Draw(Graphics graphic)
        {
            Pen pen = new Pen(Color.Black, 1);
            SolidBrush brush = new SolidBrush(Color.Black);
            Font font = new System.Drawing.Font("Times New Roman", 8, FontStyle.Regular);
            int rectangleWidth = _width;
            graphic.DrawRectangle(pen, new Rectangle(new Point(_x, _y), new Size(rectangleWidth, 20)));
            graphic.DrawString(_entityName, font, brush, _x+(rectangleWidth /4)  , _y+5);
            if (_parent != null)
            {
                DrawLine(graphic, pen);
            }
            pen.Dispose();
            brush.Dispose();
        }
        public void DrawLine(Graphics graphic, Pen pen)
        {
            pen.StartCap = LineCap.ArrowAnchor;
            pen.EndCap = LineCap.Square;

            graphic.DrawLine(pen, new Point(_x + 5, _y), new Point(_parent.x+_parent.width, _parent.y + 20));
        }
    }
}
